package com.smartsleep;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;

public class KnowledgeFragment extends Fragment implements OnClickListener {
	
	private FragmentActivity mActivity;
	
	
	 @Override
	 public View onCreateView(LayoutInflater inflater, ViewGroup container,  
	         Bundle savedInstanceState) {  
	     View view = inflater.inflate(R.layout.fragment_knowledge, container, false);  
	     return view;  
	 }
	 
	 @Override
	 public void onActivityCreated(Bundle savedInstanceState) {  
	     super.onActivityCreated(savedInstanceState);  
	     
	     View category1 = getActivity().findViewById(R.id.categ1);
	     View category2 = getActivity().findViewById(R.id.categ2);
	     View category3 = getActivity().findViewById(R.id.categ3);
	     View category4 = getActivity().findViewById(R.id.categ4);
	     View category5 = getActivity().findViewById(R.id.categ5);
	     View category6 = getActivity().findViewById(R.id.categ6);

	     category1.setOnClickListener(this);
	     category2.setOnClickListener(this);
	     category3.setOnClickListener(this);
	     category4.setOnClickListener(this);
	     category5.setOnClickListener(this);
	     category6.setOnClickListener(this);
	 }	 	     
	 
	 @Override
	 public void onClick(View v) {
		 // TODO Auto-generated method stub
		 switch(v.getId()){
		 case R.id.categ1:
			 startIntents(1);
			 break;
		 case R.id.categ2:
			 startIntents(2);
			 break;
		 case R.id.categ3:
			 startIntents(3);
			 break;
		 case R.id.categ4:
			 startIntents(4);
			 break;
		 case R.id.categ5:
			 startIntents(5);
			 break;
		 case R.id.categ6:
			 startIntents(6);
			 break;
		 }

	 }
	 
	 public void startIntents(int categNum){
		 Intent i = new Intent();
		 mActivity = getActivity();
		 Bundle bd = new Bundle();
		 bd.putInt("categNum", categNum);
		 i.putExtra("attachment", bd);
		 Log.i("categNum", String.valueOf(categNum));
		 Log.i("mActivity",mActivity.toString());
		 i.setClass(mActivity, KnowledgeList.class);
	 	 startActivity(i);
	 }
}
